<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="cmd.css" rel="stylesheet" type="text/css">
<title>批处理实例菜单_2</title>
</head>

<body>
<p><a href="./GRUB4DOS11批处理实例菜单.htm">批处理实例脚本</a> <span class="Notes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span class="Notes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>批处理实例脚本_2 <span class="Notes">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="./GRUB4DOS11批处理实例菜单_3.htm">批处理实例脚本_3</a></p>
<p><span class="Options">!BAT</span><br>
  <span class="Notes">::GRUB4DOS 简易批处理脚本 by chenall ; 修改：zxw （无需WENV版） </span><br>
  <span class="bat">debug</span> <span class="Options">off</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;关闭debug模式</span>  <br>
  <span class="bat">checkrange</span> <strong>20110111:-1</strong> <span class="bat">read</span> <strong>0x8278</strong> <span class="Options">||</span> <span class="bat">echo</span> <strong>Err.version </strong><span class="Options">&amp;&amp;</span> <span class="bat">exit 1</span><br>
  ::<span class="Notes">&nbsp;&nbsp;&nbsp;检测grldr版本，若是2011年01月11日前编译的就显示 <strong>Err.version</strong>，并退出批处理的执行</span>  <br>
  <span class="bat">set</span> <strong>runs=%~nx0</strong> <span class="Options">&amp;&amp;</span> <span class="bat">delmod</span> <span class="Options">-l</span> <strong>%~nx0</strong> <span class="Options">|| </span><span class="bat">insmod</span> <strong>%0</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将本脚本名（包含后缀名）保存至 runs 变量，并检测本脚本是否已加载至内存中，没有的话就加载至内存中</span><br>
  <span class="bat">if</span> <span class="Options">/i</span> <strong>&quot;%1&quot;==&quot;%~nx1&quot;</strong> <span class="bat">set</span> <span class="Options">/u</span> <strong>path=/BOOT/IMGS/ </strong><span class="Options">|| </span><span class="bat">set</span> <span class="Options">/u</span> <strong>path=%path%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;如果参数1是不包含路径的文件名，就使用默认文件目录/BOOT/IMGS/，否则使用变量 path 的值作为默认目录</span><br>
  <span class="bat">find </span><span class="Options">--set-root</span> <span class="bat">ls</span> <strong>%path%</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;使用find命令配合ls命令确定变量 path 所指的文件夹是否存在</span><br>
  <span class="bat">if</span> <span class="Options">not</span> <strong>#%~x1==# </strong><span class="bat">goto</span> <strong>%~x1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;如果参数1的后缀名不为空的话就跳转到以该后缀名为名的标签执行</span><br>
  <span class="bat">exit</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理的执行</span></p>
<p><span class="cmd">:FIND</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名,本段脚本用来查找文件</span><br>
  <span class="bat">echo</span> <span class="Options">-e \n</span> <strong>Now loading %1...</strong><span class="Options">\n</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;在屏幕上输出提示信息</span><br>
  <span class="bat">if </span><span class="Options">not exist</span> <strong>%~pnx1</strong><span class="Options"> &amp;&amp;</span><span class="bat"> find</span> <span class="Options">--set-root</span> <strong>%~pnx1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;如果当前设备下没有参数1指定的文件，就在所有设备上寻找</span><br>
<span class="bat">exit</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理的执行</span></p>
<p> <span class="cmd">:.IMG<br>
:.IMA<br>
:.GZ</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，本段脚本用来启动软驱类镜像（可经过gzip压缩）</span><br>
  <span class="bat">call</span> <strong>:FIND %1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将参数1作为新参数传递给FIND标签执行</span><br>
  <span class="bat">map</span> <span class="Options">–mem</span> <strong>%~pnx1</strong> <span class="bat">(fd0)</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将参数1指定的软驱镜像载入内存后仿真为第一软驱(fd0)</span><br>
  <span class="bat">map</span> <span class="Options">--hook</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;使仿真生效</span> <br>
  <span class="bat">rootnoverify</span> <strong>(fd0) </strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;设置(fd0)为根设备，忽略测试该分区的文件系统是否可以识别</span><br>
  <span class="bat">chainloader</span> <strong>+1 </strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;链式加载(fd0)的第一个扇区内容</span><br>
  <span class="bat">boot  </span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;确定进行启动</span><br>
  <span class="bat">exit</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理的执行</span></p>
<p><span class="cmd">:.BIN</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，本段脚本用来启动bin引导文件</span>  <br>
  <span class="bat">call</span> <strong>:FIND %1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将参数1作为新参数传递给FIND标签执行</span><br>
  <span class="bat">checkrange</span> <strong>0x21</strong> <span class="bat">read</span> <strong>0x8280 </strong><span class="Options">||</span> <span class="bat">map</span> <span class="Options">--in-place</span> <strong>()+1 (hd0) </strong><span class="Options">&amp;&amp; </span><span class="bat">map</span> <span class="Options">–hook</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;判断当前是否为pxe启动，不是的话进行特殊处理，使bin文件误认为从hd0设备启动</span><br>
  <span class="bat">chainloader</span> <span class="Options">--force</span> %~pnx1<br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;强制加载参数1指定的文件</span><br>
  <span class="bat">boot </span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;确定进行启动</span><br>
  <span class="bat">exit</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理的执行</span></p>
<p><span class="cmd">:.ISO</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，本段脚本用来启动iso镜像文件</span>  <br>
  <span class="bat">call</span> <strong>:FIND %1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;将参数1作为新参数传递给FIND标签执行</span>  <br>
<span class="bat">map</span> <strong>%~pnx1</strong> <span class="bat">(0xff)</span> <span class="Options">||</span> <span class="bat">map</span> <span class="Options">–mem</span> <strong>%~pnx1</strong> <span class="bat">(0xff)</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;先尝试直接仿真参数1指定的iso镜像为(0xff)光驱设备，失败的话将ISO镜像载入内存后仿真为(0xff)光驱设备</span><br>
<span class="bat">map</span> <span class="Options">–hook</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;使仿真生效</span><br>
<span class="bat">chainloader</span><strong> (0xff)</strong><br>
<span class="Notes">:: &nbsp;&nbsp;&nbsp;从(0xff)设备启动 </span><br>
<span class="bat">boot </span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;确定进行启动</span><br>
<span class="bat">exit</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理的执行</span></p>
<p><span class="cmd">:.AUTOMENU</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，本段脚本用来生成自动菜单</span>  <br>
  <span class="bat">debug</span> <strong>1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 开启debug模式</span><br>
  <span class="bat">find</span> <span class="Options">--set-root |</span> <span class="bat">set</span> <strong>bd=</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 获取当前设备号，并将其赋给变量 bd</span><br>
  <span class="bat">debug</span><strong> 0</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 关闭debug模式，本处开启又关闭debug模式是为了获得find命令的返回值</span><br>
  <span class="bat">echo</span> <span class="Options">-e</span> <strong>default 1<span class="Options"> \n</span>color white/blue blue/yellow light-red/blue 10<span class="Options">\n</span>timeout 10<span class="Options">\n</span></strong> <span class="Options">&gt;</span> <strong>(md)0x3000+0x10</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 将该字符串写入到内存6M开始的，长度为8K的区域，使用 \n 进行换行写入，定义生成的菜单文件等待时间和默认项菜单颜色</span><br>
  <span class="bat">set</span><strong> i=901 </strong><span class="Options">&amp;&amp; </span> <span class="bat">echo </span> <span class="Options">-e </span> <span class="Options">\n</span><strong>title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AUTOMENU FOR %bd%%%path%</strong> <span class="Options">\\n\n</span><strong>clear</strong> <span class="Options">&gt;&gt; </span> (md)0x3000+0x10<br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 设置变量 i 值为901，为菜单项自动编号做准备<br>
  ::&nbsp;&nbsp;&nbsp; 将字符串追加写入到内存中，使用 \n 进行换行写入，定义生成的菜单文件首菜单项标题（这个纯粹是为了美观）</span><br>
  <span class="bat">ls</span> <strong>%path%</strong> <span class="Options">|</span> <strong>call :MAKEMENU</strong><span class="Options"> ||</span> <span class="bat">echo </span> <span class="Options">-n</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 使用ls命令列出变量path指定的文件夹中的文件，并作为参数通过管道命令 | 传递给 MAKEMENU 标签段脚本进行处理</span><br>
  <span class="bat">echo </span> <span class="Options">-e </span> <span class="Options">\n</span><strong>title %i:~1%. RUN MainMenu</strong><span class="Options">\\n\t</span><strong>configfile (md)4+8</strong><span class="Options">\n</span><strong>configfile (md)4+8</strong> <span class="Options">&gt;&gt; </span> <strong>(md)0x3000+0x10</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 待所有文件均处理完后追加写入最后一项菜单，返回主菜单 </span><br>
  <span class="bat">set</span> <strong>i=</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 清除变量 i 的值</span><br>
  <span class="bat">configfile</span> <strong>(md)0x3000+0x10</strong><br>
  ::&nbsp;&nbsp;&nbsp; 加载写入内存区块中的菜单<br>
<span class="bat">exit</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理的执行</span></p>
<p><span class="cmd">:MAKEMENU</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，本段脚本用来生成菜单正文</span><br>
  <span class="bat">if</span> <strong>#%1==#</strong> <span class="bat">exit</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 如果参数1为空就退出批处理的执行</span><br>
  <span class="bat">if</span> <span class="Options">/i</span> <strong>&quot;%~x1&quot;==&quot;.TXT&quot;</strong> <span class="bat">goto</span> <strong>:shift1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 检测参数1的后缀名，为txt文件就跳转到shift1标签，通过shift命令跳过这个文件</span><br>
  <span class="bat">if</span> <strong>#%~x1==#</strong><span class="bat"> goto</span> <strong>:shift1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 检测参数1的后缀名，为空就跳转到shift1标签，通过shift命令跳过这个文件</span><br>
  <span class="bat">set</span> <strong>m=%~n1</strong> <span class="Options">&amp;&amp; </span> <span class="bat">if</span> <span class="Options">/i</span> <strong>&quot;%m:~6,1%&quot;==&quot;~&quot; </strong><span class="bat">goto</span> <strong>:shift1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 设置变量 m 的值为参数1所指代文件的文件名，并检测该值的第七个字符是否为 &quot;~&quot; ，是的话就跳转到shift1标签，通过shift命令跳过这个文件<br>
::&nbsp;&nbsp;&nbsp; 设置本行检测的目的是因为文件名不符合8.3命名格式时，生成的自动菜单可能出现雷同菜单项，当然这种检测不是很严格，<br>
::&nbsp;&nbsp;&nbsp; 可能还是会出现，增强版RUN已解决这个问题。</span><br>
  <span class="bat">if</span> <span class="Options">exist</span> <strong>%~n1.TXT</strong> <span class="Options">&amp;&amp; </span> <strong>cat %~n1.TXT</strong> <span class="Options">&gt;&gt; </span> <strong>(md)0x3000+0x10</strong> <span class="Options">&amp;&amp; </span> <span class="bat">echo </span> <span class="Options">-n</span> <span class="Options">\n\t</span><strong>%bd%%%path%%%~nx1</strong> <span class="Options">&gt;&gt; </span> <strong>(md)0x3000+0x10</strong> <span class="Options">!</span> <span class="bat">echo </span> <span class="Options">-e </span><strong> title %i:~1%. RUN %~nx1</strong><span class="Options">\\n\t</span><strong>%bd%%%path%%%~nx1</strong> <span class="Options">&gt;&gt;<strong> </strong></span><strong> (md)0x3000+0x10</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;  检测和参数同名的txt文件是否存在，存在的话将txt文本内容作为该项菜单的标题，否则使用参数名作为该项菜单的标题，追加写入内存中</span><br>
  <span class="bat">echo </span> <span class="Options">-e </span> <span class="Options">\n</span><strong>%runs% %path%%%~nx1</strong><span class="Options">\n</span><strong>boot</strong><span class="Options">\n &gt;&gt; </span><strong> (md)0x3000+0x10</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;追加写入本项菜单的执行命令</span><br>
  <span class="bat">set</span> <span class="Options">/a</span><strong> i=%i%+1</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;菜单项编号+1，为下一项菜单编号做准备</span><br>
  <span class="cmd">:shift1</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp;标签名，本段脚本用来跳过处理不符合规定的文件</span><br>
  <span class="bat">shift</span><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; shift命令</span><br>
  <span class="bat">goto</span> <strong>:MAKEMENU</strong><br>
  <span class="Notes">::&nbsp;&nbsp;&nbsp; 跳转到 MAKEMENU 标签段脚本执行</span><br>
<span class="bat">exit</span><br>
<span class="Notes">::&nbsp;&nbsp;&nbsp;退出批处理的执行</span></p>
</body>
</html>
